package com.hedl.elasticsearch.styud_test;

import com.hedl.elasticsearch.po.Apple;
import com.hedl.elasticsearch.po.User;
import com.hedl.elasticsearch.test.TestTool;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * ProjectName: stuy-elasticsearch
 * DateTime: 2023/9/18 19:21
 * Author: Big Watermelon
 * Description:
 */
@SpringBootTest
public class Study {

    @Test
    public void arrayListTest(){
        List<User> list = new ArrayList<>();

        for (int i = 1;i <= 100;i++){
            User user = new User("大西瓜","男",i);
            list.add(user);
        }
        System.out.println(list.toString());


    }

    @Test
    public void arrayListTest_1(){
        List<User> list = new ArrayList<>();
        User user;

        for (int i = 0;i <= 10;i++){
            user = new User();
            user.setName("大西瓜");
            user.setSex("男");
            user.setAge(i);
            list.add(user);
        }
        System.out.println(list.toString());
    }

    @Test
    public void listFilter1(){
        Apple apple;
        List<Apple> listApple = new ArrayList<>();
        for (int i = 1;i <= 10;i++){
            apple = new Apple("大西瓜"+i,"红色"+i,100+i);
            listApple.add(apple);
        }
        System.out.println(listApple);

        for (Apple apple1 : listApple) {
            if ("大西瓜6".equals(apple1.getName())){
                System.out.println("找到了");
            }
        }
    }

    @Test
    public void listFilter2(){


        Apple apple;
        List<Apple> listApple = new ArrayList<>();
        for (int i = 1;i <= 10;i++){
            apple = new Apple("大西瓜"+i,"红色"+i,100+i);
            listApple.add(apple);
        }

        //封装函数逻辑
        Predicate<Apple> isName = apple1 -> apple1.getName().equals("大西瓜6");
        //这里是看不到封装的函数逻辑的
        System.out.println(isName);
        //List<Apple> collect = listApple.stream().filter(isName).collect(Collectors.toList());
        //System.out.println(collect);
        TestTool<Apple> testTool = new TestTool<>();
        List<Apple> list = testTool.filterApples(listApple, isName);
        System.out.println(list);
    }
}